package cn.ikun.wy.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class AppJdbcInsert {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/wy666";
        String username = "root";
        String password = "wy2wxyan";
        Connection connection = DriverManager.getConnection(url, username, password);
        Statement statement = connection.createStatement();

        // 执行 select                 需要调用 executeQuery 方法
        // 执行 insert、update、delete 需要调用 executeUpdate 方法
        String sql = "INSERT INTO `wy` (`username`, `password`) VALUES ('tom', MD5('132'));";
        // 执行 update 语句，得到受影响的行数
        int i = statement.executeUpdate(sql);
        if (i > 0) {
            System.out.println("插入成功！");
        }
    }

}
